import crypto from 'crypto'
import {hash} from 'blake3'
import CONFIG from '@rmw/config'
import BASE64 from 'urlsafe-base64'
import machineId from 'node-machine-id'
{machineIdSync} = machineId

export default do =>

  {SEED} = CONFIG
  if SEED
    seed = BASE64.decode SEED
  else
    seed = crypto.randomBytes(32)
    CONFIG.SEED = BASE64.encode seed

  mid = machineIdSync(original: true)
  hash(
    Buffer.concat [
      Buffer.from(mid,"binary")
      seed
    ]
  )
